home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Plotting / aa_Intel_Only / Gnuplot / GnuplotSource / DataOptionsPanel.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  6.8 KB  |  369 lines

  1. /*
  2.  *  Copyright (C) 1993  Robert Davis
  3.  *
  4.  *  This program is free software; you can redistribute it and/or
  5.  *  modify it under the terms of Version 2, or any later version, of 
  6.  *  the GNU General Public License as published by the Free Software 
  7.  *  Foundation.
  8.  */
  9.  
  10.  
  11. static char RCSId[]="$Id: DataOptionsPanel.m,v 1.10 1993/05/24 03:59:41 davis Exp $";
  12.  
  13.  
  14. #import <appkit/Application.h>
  15. #import <appkit/Cell.h>
  16. #import <appkit/Panel.h>
  17. #import <appkit/TextField.h>
  18.  
  19. #import <objc/NXStringTable.h>
  20.  
  21. #import "DataOptionsPanel.h"
  22. #import "DataFilePane.h"
  23. #import "DataFileThreeDPane.h"
  24. #import "DataPane.h"
  25. #import "EditMatrix.h"
  26. #import "FunctionPane.h"
  27. #import "FunctionObject.h"
  28. #import "GnuplotPlot.h"
  29. #import "NoDataPane.h"
  30. #import "Pane.h"
  31. #import "Status.h"
  32. #import "SubObjectCategory.h"
  33.  
  34. #define    FUNCTION_PANE        0
  35. #define    DATAFILE_PANE        1
  36. #define    DATAFILE_THREED_PANE    2
  37. #define    NO_PANE            3
  38.  
  39.  
  40.  
  41. @interface DataOptionsPanel (Private)
  42.  
  43. - _setupPane:(Pane *)aPane;
  44. - _selectPane:(int)aPane;
  45. - _swapPane:(Pane *)new;
  46. - _updatePanel;             /** Overridden from OptionsPanel (Private) **/
  47.  
  48. @end
  49.  
  50.  
  51.  
  52. @implementation DataOptionsPanel
  53.  
  54. - init
  55. {
  56.     NXSize interCellSpacing = {1.0, 1.0};
  57.  
  58.     [super init];
  59.  
  60.     [NXApp loadNibSection: "DataOptionsPanel.nib"
  61.             owner: self
  62.         withNames: NO
  63.          fromZone: [self zone]];
  64.  
  65.     [panel setFrameUsingName:"DataOptionsPanel"];
  66.     [panel setFrameAutosaveName:"DataOptionsPanel"];
  67.     [panel setBecomeKeyOnlyIfNeeded:YES];
  68.  
  69.     isOwnerCurrent = YES;
  70.     isMult = NO;
  71.  
  72.     return self;
  73. }
  74.  
  75.  
  76. - free
  77. {
  78.     [stringSet free];
  79.     [functionPane free];
  80.     [dataFilePane free];
  81.     [dataFileThreeDPane free];
  82.     [noPane free];
  83.  
  84.     return [super free];
  85. }
  86.  
  87.  
  88. - setOwner:anObject
  89. {
  90.     if ([anObject respondsTo:@selector(functionsMatrix)]) {
  91.     owner = anObject;
  92.     functionsMatrix = [owner functionsMatrix];
  93.     }
  94.  
  95.     return self;
  96. }
  97.  
  98.  
  99. - forceUpdate
  100. {
  101.     id        mainWindow;
  102.  
  103.     if (isOwnerCurrent && (mainWindow = [NXApp mainWindow])) {
  104.  
  105.     status = [[mainWindow delegate] status];
  106.     function = [[functionsMatrix selectedCell] subObject];
  107.     isMult = !function && [functionsMatrix multipleCellsSelected];
  108.  
  109.     } else {
  110.  
  111.     status = nil;
  112.     function = nil;
  113.     isMult = NO;
  114.     }
  115.  
  116.     [self _updatePanel];
  117.  
  118.     return self;
  119. }
  120.  
  121.  
  122. - windowDidUpdate:sender
  123. {
  124.     id        mainWindow;
  125.     id        newStatus, newFunction;
  126.     BOOL    newMult;
  127.  
  128.     if (isOwnerCurrent && (mainWindow = [NXApp mainWindow])) {
  129.  
  130.     newStatus = [[mainWindow delegate] status];
  131.     newFunction = [[functionsMatrix selectedCell] subObject];
  132.     newMult = [functionsMatrix multipleCellsSelected];
  133.  
  134.     } else {
  135.  
  136.     newStatus = nil;
  137.     newFunction = nil;
  138.     newMult = NO;
  139.  
  140.     }
  141.  
  142.     if ((newStatus != status) || (newFunction != function)
  143.     || (newMult != isMult)) {
  144.     status = newStatus;
  145.     function = newFunction;
  146.     isMult = newMult;
  147.     [self _updatePanel];
  148.     }
  149.  
  150.     return self;
  151. }
  152.  
  153.  
  154.  
  155.  
  156. - ownerDidSwapIn:sender
  157. {
  158.     isOwnerCurrent = YES;
  159.     [self forceUpdate];
  160.  
  161.     return self;
  162. }
  163.  
  164.  
  165. - ownerDidSwapOut:sender
  166. {
  167.     isOwnerCurrent = NO;
  168.     [self forceUpdate];
  169.  
  170.     return self;
  171. }
  172.  
  173.  
  174. - function
  175. {
  176.     return function;
  177. }
  178.  
  179.  
  180. - functionsMatrix
  181. {
  182.     return functionsMatrix;
  183. }
  184.  
  185.  
  186. - setFunctionTitle:sender
  187. {
  188.     int        i;
  189.     Cell    *cell;
  190.     id        lastHighlightedObject = nil;
  191.     BOOL    didChange = NO;
  192.  
  193.   
  194.     /* Set title of all selected functions. */
  195.  
  196.     for (i = [functionsMatrix cellCount] - 1 ; i >= 0 ; i--) {
  197.     cell = [functionsMatrix cellAt:i:0];
  198.     if ([cell isHighlighted])  {
  199.         lastHighlightedObject = [cell subObject];
  200.         [lastHighlightedObject setTitle: [titleField stringValue]];
  201.         didChange = YES;
  202.     }
  203.     }
  204.  
  205.     /*  The subObjects may have fixed the title  */
  206.     [titleField setStringValue:[lastHighlightedObject title]];
  207.   
  208.     /* 
  209.      *  We changed the functions directly instead of going through 
  210.      *  status, so we must inform status of the change.
  211.      */
  212.  
  213.     if (didChange)
  214.     [status reportSettingsChange:self];
  215.  
  216.     return self;
  217. }
  218.  
  219.  
  220. // Shuts up the compiler about unused RCSId
  221. - (const char *) rcsid
  222. {
  223.     return RCSId;
  224. }
  225.  
  226.  
  227.  
  228. @end
  229.  
  230.  
  231.  
  232.  
  233.  
  234. @implementation DataOptionsPanel (Private)
  235.  
  236. - _setupPane:(Pane *)aPane
  237. {
  238.     if (aPane) {
  239.         View    *panesView = [aPane view];
  240.  
  241.         [[panel contentView] addSubview: panesView];
  242.         [[panesView allocateGState] lockFocus];
  243.         [panesView unlockFocus];
  244.         [panesView moveTo:0:0];
  245.     }
  246.  
  247.     return self;
  248. }
  249.         
  250.  
  251. - _selectPane:(int)aPane
  252. {
  253.     switch (aPane) {
  254.  
  255.     case FUNCTION_PANE:
  256.         if (!functionPane) {
  257.             functionPane = [[FunctionPane allocFromZone:[self zone]] init];
  258.             [self _setupPane:functionPane];
  259.         }
  260.         [self _swapPane:functionPane];
  261.         break;
  262.  
  263.     case DATAFILE_PANE:
  264.         if (!dataFilePane) {
  265.             dataFilePane = [[DataFilePane allocFromZone:[self zone]] init];
  266.             [self _setupPane:dataFilePane];
  267.         }
  268.         [self _swapPane:dataFilePane];
  269.         break;
  270.  
  271.     case DATAFILE_THREED_PANE:
  272.         if (!dataFileThreeDPane) {
  273.             dataFileThreeDPane =
  274.         [[DataFileThreeDPane allocFromZone:[self zone]] init];
  275.             [self _setupPane:dataFileThreeDPane];
  276.         }
  277.         [self _swapPane:dataFileThreeDPane];
  278.         break;
  279.  
  280.     default:
  281.         if (!noPane) {
  282.             noPane = [[NoDataPane allocFromZone:[self zone]] init];
  283.             [self _setupPane:noPane];
  284.         }
  285.         [self _swapPane:noPane];
  286.         break;
  287.  
  288.     }
  289.  
  290.     return self;
  291. }
  292.  
  293.  
  294.  
  295. - _swapPane:(Pane *)new
  296. {
  297.     /*  
  298.      *  If the new pane is not already visible, move it into the panel.
  299.      */
  300.     
  301.     if (new != currentPane) {
  302.  
  303.         [[panel contentView] replaceSubview:[currentPane view]
  304.                        with:[new view]];
  305.         [currentPane didSwapOut:self];
  306.  
  307.     /*  
  308.      *  Notice we give ourselves as the "doc" when updating one of 
  309.      *  our Panes.  It may then query us for current function.
  310.      */
  311.         [[new didSwapIn:self] updateStatus:status doc:self];
  312. //        [panel display];
  313.  
  314.         [panel setTitle:[new title]];
  315.         [panel setMiniwindowIcon:[new icon]];
  316.  
  317.         currentPane = new;
  318.  
  319.     }
  320.  
  321.     return self;
  322. }
  323.  
  324.  
  325.  
  326. - _updatePanel
  327. {
  328.     BOOL    enabled = (isOwnerCurrent && status);// is status necessary?
  329.  
  330.     [panel disableDisplay];
  331.  
  332.     if (enabled && isMult) {
  333.  
  334.     [stringField setStringValue:[stringSet valueForStringKey:"multiple"]];
  335.     [titleField setStringValue:""];
  336.     [self _selectPane:FUNCTION_PANE];
  337.  
  338.     } else if (enabled && function) {
  339.  
  340.     [stringField setStringValue:[function stringValue]];
  341.     [titleField setStringValue:[function title]];
  342.  
  343.     if ([function isDataFile]) {
  344.         if ([status isThreeD])
  345.         [self _selectPane:DATAFILE_THREED_PANE];
  346.         else
  347.         [self _selectPane:DATAFILE_PANE];
  348.     } else
  349.         [self _selectPane:FUNCTION_PANE];
  350.  
  351.     } else {
  352.  
  353.     [stringField setStringValue:[stringSet valueForStringKey:"none"]];
  354.     [titleField setStringValue:""];
  355.     [self _selectPane:NO_PANE];
  356.  
  357.     }
  358.  
  359.     [titleField setEnabled:enabled && (isMult || function)];
  360.     [currentPane updateStatus:status doc:self];
  361.  
  362.     [panel reenableDisplay];
  363.     [panel display];
  364.  
  365.     return self;
  366. }
  367.  
  368. @end
  369.